package com.moxing.admin.service.impl;

import com.moxing.admin.common.dto.request.LoginRequestParam;
import com.moxing.admin.common.entity.User;
import com.moxing.admin.common.utils.Md5Util;
import com.moxing.admin.service.LoginService;
import com.moxing.admin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(value = "LoginService")
public class LoginServiceImpl implements LoginService {

    @Autowired
    private UserService userService;
    @Override
    public User login(LoginRequestParam param) {
        User user = userService.getUserByPhone(param.getUsername());
        if(user==null){
            throw new RuntimeException("用户未注册");
        }
        if(!Md5Util.md5Password(param.getPassword()).equals(user.getPassword())){
            throw new RuntimeException("密码错误");
        }
        if(user.getAccountStatus()==0){
            throw new RuntimeException("账号禁用，请解锁");
        }
        return user;
    }
}
